//
//  SubscribeViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/9/20.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "SubscribeViewController.h"
#import "RentVieitor.h"
#import "SubScribeCell.h"

@interface SubscribeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation SubscribeViewController {
    
    UICollectionView *_collectionView;
}

- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = BackgroundColor;
    [self creatnativeView];
    [self creatView];
}

- (void)creatnativeView {
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 60)];
    headView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:headView];
    
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(15, 30, 10,15 );
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"箭头左"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:leftBtn];
    
    UIButton * canceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [canceBtn setTitle:@"|  取消" forState:UIControlStateNormal];
    [canceBtn setTitleColor:[Utils colorConvertFromString:@"#101010"] forState:UIControlStateNormal];
    canceBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    CGSize size = [@"|  取消" boundingRectWithSize:CGSizeMake(300, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:canceBtn.titleLabel.font} context:nil].size;
    canceBtn.frame = CGRectMake(KWidth-15-size.width, 30,size.width,15);
    
    [canceBtn addTarget:self action:@selector(cnaceAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:canceBtn];
    
    UIButton * allBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [allBtn setTitle:@"全选" forState:UIControlStateNormal];
    [allBtn setTitleColor:[Utils colorConvertFromString:@"#101010"] forState:UIControlStateNormal];
    allBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    CGSize size2 = [@"全选" boundingRectWithSize:CGSizeMake(300, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:allBtn.titleLabel.font} context:nil].size;
    allBtn.frame = CGRectMake(KWidth-22.5-size.width-size2.width, 30,size2.width,15);
    
    [allBtn addTarget:self action:@selector(allAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:allBtn];
    
    //分割线
    CALayer *MlineLayer = [CALayer layer];
    MlineLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    MlineLayer.frame = CGRectMake(0 ,60, KWidth, 1);
    [self.view.layer addSublayer:MlineLayer];
    
}

- (void)creatView {
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    //    [flowLayout setItemSize:CGSizeMake((MWidth-20)/4, 100)];//设置cell的尺寸
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//设置其边界
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 65, KWidth, KHeight-65)collectionViewLayout:flowLayout];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.showsVerticalScrollIndicator = NO;
    _collectionView.showsHorizontalScrollIndicator = NO;
    _collectionView.backgroundColor = [UIColor clearColor];
    [_collectionView registerClass:[SubScribeCell class] forCellWithReuseIdentifier:@"_cell"];
    [self.view addSubview:_collectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 10;
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    SubScribeCell  *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"_cell" forIndexPath:indexPath];
    return cell;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(KWidth, 170);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5, 5, 5, 5);//分别为上、左、下、右
}


//取消
- (void)cnaceAction {
    
    
}

//全选
- (void)allAction {
    
}

- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
